package com.yeebo.utils;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class DynamicRuleUtils {

    public static void main(String[] args) {
        ScriptEngineManager sem = new ScriptEngineManager();
        ScriptEngine engine = sem.getEngineByName("javascript");
        try {
            String originalExpression = "x >= 20 && x <= 40";
            engine.put("x", 18);
            Object result = engine.eval(originalExpression);
            System.out.println("结果类型:" + result.getClass().getName() + ",计算结果:" + result);
        } catch (ScriptException e) {
            e.printStackTrace();
        }
    }

}
